package com.trs.crypt;

import java.io.File;

/**
 * @ClassName KeyJNIV124
 * @Description 描述
 * @Detail detail
 * @Author MyPC
 * @Date 2020/12/11
 * @Version 1.0
 */
public class KeyJNIV124 {
    private static int g_iDLLErrorCode = 0;
    private static String g_sDLLErrorString = null;

    public KeyJNIV124() {
    }

    private static String getOSName() {
        String OSName = System.getProperty("os.name");
        if (OSName == null) {
            return null;
        } else {
            OSName = OSName.toLowerCase();
            if (OSName.startsWith("windows")) {
                OSName = "windows";
            } else if (OSName.startsWith("linux")) {
                OSName = "linux";
            } else if (!OSName.startsWith("solaris") && !OSName.startsWith("sun")) {
                if (!OSName.startsWith("hp-ux") && !OSName.startsWith("hpux")) {
                    if (OSName.startsWith("aix")) {
                        OSName = "aix";
                    } else if (OSName.startsWith("mac")) {
                        OSName = "mac";
                    } else if (OSName.indexOf("bsd") != -1) {
                        OSName = "bsd";
                    } else if (OSName.indexOf("netware") != -1) {
                        OSName = "netware";
                    }
                } else {
                    OSName = "hpux";
                }
            } else {
                OSName = "solaris";
            }

            return OSName;
        }
    }

    private static String getOSArch() {
        String OSArch = System.getProperty("os.arch");
        if (OSArch == null) {
            return null;
        } else {
            OSArch = OSArch.toLowerCase();
            if (!OSArch.equalsIgnoreCase("x86") && !OSArch.startsWith("pentium") && !OSArch.startsWith("i386") && !OSArch.startsWith("i486") && !OSArch.startsWith("i586") && !OSArch.startsWith("i686") && !OSArch.equalsIgnoreCase("ia32")) {
                if (!OSArch.equalsIgnoreCase("x86_64") && !OSArch.equalsIgnoreCase("x64") && !OSArch.equalsIgnoreCase("amd64")) {
                    if (OSArch.equalsIgnoreCase("sparc")) {
                        OSArch = "sparc32";
                    } else if (OSArch.equalsIgnoreCase("sparc64")) {
                        OSArch = "sparc64";
                    } else if (!OSArch.equalsIgnoreCase("ppc") && !OSArch.equalsIgnoreCase("powerpc") && !OSArch.equalsIgnoreCase("power") && !OSArch.startsWith("power_")) {
                        if (OSArch.equalsIgnoreCase("ppc64")) {
                            OSArch = "ppc64";
                        } else if (!OSArch.equalsIgnoreCase("pa_risc") && !OSArch.equalsIgnoreCase("pa_risc2.0")) {
                            if (OSArch.equalsIgnoreCase("pa_risc2.0w")) {
                                OSArch = "pa64";
                            } else if (!OSArch.equalsIgnoreCase("ia64n") && (OSArch.indexOf("itanium") == -1 || OSArch.indexOf("32") == -1)) {
                                if (OSArch.equalsIgnoreCase("ia64") || OSArch.equalsIgnoreCase("ia64w") || OSArch.indexOf("itanium") != -1 && OSArch.indexOf("64") != -1) {
                                    OSArch = "ia64";
                                }
                            } else {
                                OSArch = "ia32";
                            }
                        } else {
                            OSArch = "pa32";
                        }
                    } else {
                        OSArch = "ppc32";
                    }
                } else {
                    OSArch = "amd64";
                }
            } else {
                OSArch = "i386";
            }

            return OSArch;
        }
    }

    private static final String getHelpString() {
        String helpMsg = null;
        helpMsg = "OS: " + getOSName() + "_" + getOSArch() + ", JDK_VERSION: " + System.getProperty("java.version");
        System.out.println(helpMsg);
        return helpMsg;
    }

    public static int getDLLErrorCode() {
        return g_iDLLErrorCode;
    }

    public static String getDLLErrorString() {
        return g_sDLLErrorString;
    }

    public static native String keyIdentifyHost(Object var0, long var1);

    public static native String keyGetLocalIPs(Object var0, long var1);

    public static native String keyGetLocalMACs(Object var0, long var1);

    public static native String keyGenerateDemo(Object var0, long var1, String var3, String var4, String var5, String var6, String var7);

    public static native String keyValidateCode(Object var0, long var1, String var3, String var4, boolean var5);

    public static native Class decryptClass(Object var0, long var1, String var3, ClassLoader var4, byte[] var5);

    public static native byte[] encryptClass(Object var0, long var1, String var3, ClassLoader var4, byte[] var5);

    static {
        String HelpMsg;
        try {
            String libraryName = "trscrypt";
            HelpMsg = "/com/trs/crypt/native/" + getOSName() + "_" + getOSArch();
            String nativeLibraryName = System.mapLibraryName("trscrypt");
            boolean hasNativeLib = KeyJNILoader.hasResource(HelpMsg + "/" + nativeLibraryName);
            String tempFolder = (new File(System.getProperty("java.io.tmpdir"))).getAbsolutePath();
            File nativeLibFile = hasNativeLib ? KeyJNILoader.extractLibraryFile(HelpMsg, nativeLibraryName, tempFolder) : null;
            if (nativeLibFile != null) {
                System.load(nativeLibFile.getAbsolutePath());
            } else {
                System.loadLibrary("trscrypt");
            }

            decryptClass((Object)null, 0L, (String)null, KeyJNIV124.class.getClassLoader(), (byte[])null);
        } catch (UnsatisfiedLinkError var6) {
            g_iDLLErrorCode = 1;
            g_sDLLErrorString = var6.toString();
            HelpMsg = getHelpString();
            if (HelpMsg != null) {
                g_sDLLErrorString = g_sDLLErrorString + HelpMsg;
            }
        } catch (SecurityException var7) {
            g_iDLLErrorCode = 2;
            g_sDLLErrorString = var7.toString();
        }

    }
}
